package com.zzptc.zzsgz.bdsjws.activities;

import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.widget.Toast;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.fragments.UpdateVersionFragment;
import com.zzptc.zzsgz.bdsjws.vo.VersionInfo;

import butterknife.BindView;
import butterknife.OnClick;

public class UpdateActivity extends BaseActivity {

    @BindView(R.id.toolbar1)
    Toolbar toolbar1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_update);
        setSupportActionBar(toolbar1);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle("");
        actionBar.setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public int getContentXML() {
        return R.layout.activity_update;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {

    }

    @OnClick(R.id.LL_CheckUpdate)
    public void onViewClicked(){
        startActivityForResult(new Intent(UpdateActivity.this,CheckUpdateActivity.class),0);

    }


    public void showDialog (String msg){
        FragmentManager fm1 = getFragmentManager();
        UpdateVersionFragment u1 = UpdateVersionFragment.getUpdateVersionFragment(msg);
        u1.show(fm1,"");
    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 1:
                Toast.makeText(this, "网络较慢，无法下载", Toast.LENGTH_SHORT).show();
                showDialog("网络较慢，无法下载");
                break;
            case 2:
                Toast.makeText(this, "网络不通，请检查网络", Toast.LENGTH_SHORT).show();
                showDialog("网络不通，请检查网络");
                break;
            case 3:
                VersionInfo versionInfo = (VersionInfo) data.getSerializableExtra("VersionInfo");
                FragmentManager fm = getFragmentManager();
                UpdateVersionFragment u = UpdateVersionFragment.getUpdateVersionFragment(versionInfo);
                u.show(fm, "");

//                Toast.makeText(this, versionInfo.getApkurl(), Toast.LENGTH_SHORT).show();
//                Toast.makeText(this, "网络正常，可以下载", Toast.LENGTH_SHORT).show();
                break;
            case 4:
//                FragmentManager fm1 = getFragmentManager();
//                UpdateVersionFragment ul = new UpdateVersionFragment();
//                ul.show(fm1 , "");
                Toast.makeText(this, "当前已经是最新版本", Toast.LENGTH_SHORT).show();
                showDialog("已经是最新的版本了");
                break;
        }
    }



}
